export enum SoundName {
    /** 成功上螺丝 */
    Success_Screw,
    /** 螺丝飞向工具箱 */
    Fly_Screw,
    /** 拧螺丝 */
    Open_Screw,
    /** 拧螺丝失败 */
    Ban,
    /** 胜利结算 */
    Success,
    /** 失败结算 */
    Failed,
    Bg
}
/**
 * Sound管理类
 */
const { ccclass, property } = cc._decorator;

@ccclass
export default class C_SoundManager extends cc.Component {
    @property([cc.AudioClip])
    soundFile: cc.AudioClip[] = [];
    static instance: C_SoundManager;
    playEffect(index: number, isLoop?: boolean) {
        const sound = this.soundFile[index];
        if (sound)
            cc.audioEngine.playEffect(sound, isLoop)
        else {
            console.error("缺少音效资源：", index);
        }
    }

    _audioID
    playBg(index, isLoop: boolean = true) {
        const sound = this.soundFile[index];
        if (sound)
            this._audioID = cc.audioEngine.playMusic(sound, isLoop)
        else {
            console.error("缺少音效资源：", index);
        }
    }

    stopBg() {
        if (this._audioID) {

            cc.audioEngine.stop(this._audioID);
            this._audioID = null;
        }
    }

    protected static _soundFile: cc.AudioClip[]
    protected onLoad(): void {
        C_SoundManager.instance = this;
        C_SoundManager._soundFile = this.soundFile;
    }


}